package easyExecleTest;

import cn.cai.EasyExcelLesner;
import cn.cai.pojo.EasyExcelObj;
import com.alibaba.excel.EasyExcel;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

public class easyExecleDome {

    @Test
    void easyExcelWriteDome(){

        //实现excel写操作
        //1.设置写入有文件夹地址和excel文件名称
        String fileName = "D://dome.xlsx";
        //2.调用easyExcel
        EasyExcel.write(fileName, EasyExcelObj.class).
                sheet("学生列表1").doWrite(easyExecleDome.getData());

    }

    private static List<EasyExcelObj> getData(){
        List<EasyExcelObj> list = new ArrayList<>();
        for (int i = 0;i <100;i++){
            EasyExcelObj easyExcelObj = new EasyExcelObj();
            easyExcelObj.setName("张三"+i);
            easyExcelObj.setNo(i+1);
            list.add(easyExcelObj);
        }
        return list;
    }


    /**
     * EasyExcel写操作
     */

    @Test
    void easyExcelRead(){
        //使用easyExcel进行读操作
        String fileName = "D://dome.xlsx";
        EasyExcel.read(fileName,EasyExcelObj.class,new EasyExcelLesner())
                .sheet("学生列表1").doRead();
    }


//    @Test
//    void resdTest(){
//        File file = new File("D://dome.xlsx");
//        try {
//            FileInputStream inputStream = new FileInputStream(file);
//            List<SubjectData> subjectDataList;
//            subjectDataList = EasyExcel.read(inputStream)
//                    .head(SubjectData.class)
//                    .sheet()
//                    .doReadSync();
//            for (SubjectData subjectData:subjectDataList){
//                System.out.println(subjectData);
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//    }
}
